package com.qingke.filter;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class ValidateFilter implements Filter {

    public ValidateFilter() {
    	
    }

	public void destroy() {
		
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		System.out.println("before chain do filter");
		printAttribute(request,"validate");
//		((HttpServletRequest)request).getSession();
		chain.doFilter(request, response);
		System.out.println("after chain do filter");
	}

	public void init(FilterConfig fConfig) throws ServletException {
		
	}
	
	public void printAttribute(ServletRequest request, String phase){
		Enumeration<String> names=request.getAttributeNames();
		System.out.println("current phase "+phase);
		while(names.hasMoreElements()){
			String name=names.nextElement();
			System.out.println("req attr "+name+"="+request.getAttribute(name));
		}
	}
}
